%%%-----------------------------------
%%% @Module  : pt_29
%%% @Author  : xws
%%% @Created : 2017.2.22
%%% @Description: pt_29
%%%-----------------------------------
-module(pt_29).
-export([read/2, write/2]).
-include("common.hrl").
-include("proto_14_shop.hrl").
-include("proto_29_rank.hrl").

%%
%%客户端 -> 服务端 ----------------------------
%%

%% 29000 c2s获取兑换排行榜
read(29000, Bin) ->
	{ClientData, _} = proto_read:unpack(c2s_get_exchange_rank, Bin),	
	{c2s_get_exchange_rank, PlayerId} = ClientData,
    {ok, [PlayerId]};

%% 29001 c2s获取历史兑换记录
read(29001, Bin) ->
	{ClientData, _} = proto_read:unpack(c2s_get_exchange_his, Bin),	
	{c2s_get_exchange_his, PlayerId} = ClientData,
    {ok, [PlayerId]};

%% 29002 c2s获取金币排行榜
read(29002, Bin) ->
    {ClientData, _} = proto_read:unpack(c2s_get_coin_rank, Bin),    
    {c2s_get_coin_rank, PlayerId} = ClientData,
    {ok, [PlayerId]};

%% 29003 c2s获取胜率排行榜
read(29003, Bin) ->
    {ClientData, _} = proto_read:unpack(c2s_get_win_rate_rank, Bin), 
    {c2s_get_win_rate_rank, PlayerId} = ClientData,
    {ok, [PlayerId]};

%% 29004 获取排行榜名次奖励
read(29004, Bin) ->
    {ClientData, _} = proto_read:unpack(c2s_get_rank_award, Bin), 
    {c2s_get_rank_award, RankType} = ClientData,
    {ok, [RankType]};

%% 29005 获取玩家排行榜数据
read(29005, Bin) ->
    {ClientData, _} = proto_read:unpack(c2s_get_rank_award, Bin), 
    {c2s_get_rank_award, RankType} = ClientData,
    {ok, [RankType]};

%% 29006 c2s获取充值排行榜
read(29006, Bin) ->
    {ClientData, _} = proto_read:unpack(c2s_get_recharge_rank, Bin), 
    {c2s_get_recharge_rank, PlayerId} = ClientData,
    {ok, [PlayerId]};

read(_Cmd, _R) ->
    ?ERROR_MSG("~s pt_14 reading cmd_[~p], Data:~p~n",[misc:time_format(game_timer:now()), _Cmd, _R]),
    {error, no_match}.

%%
%%服务端 -> 客户端 ------------------------------------
%%
%% 29000 c2s获取兑换排行榜
write(29000, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_get_exchange_rank, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(29000, ServerData)};

%% 29001 c2s获取历史兑换记录
write(29001, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_get_exchange_his, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(29001, ServerData)};

%% 29002 c2s获取金币排行榜
write(29002, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_get_coin_rank, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(29002, ServerData)};

%% 29003 c2s获取胜率排行榜
write(29003, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_get_win_rate_rank, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(29003, ServerData)};

%% 29004 获取排行榜名次奖励
write(29004, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_get_rank_award, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(29004, ServerData)};

%% 29005 获取玩家排行榜数据
write(29005, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_get_player_rank_data, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(29005, ServerData)};

%% 29006 获取充值排行榜
write(29006, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_get_recharge_rank, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(29006, ServerData)};

write(Cmd, _R) ->
    ?ERROR_MSG("~s pt_14 writting cmd_[~p], Data:~p~n",[misc:time_format(game_timer:now()), Cmd, _R]),
    {ok, pt:pack(0, <<>>)}.
